###############################################################################
# Filename: Overload.py
# Author: Koy Dooley
# Revision History: 
# Description: Sets up Overload Protection for a server
# Usage: 
# java weblogic.WLST Overload.py [ -u user -p password -u admin_url -s server ] | [ -f property file ]
###############################################################################
import getopt, sys

#loadProperties('${ANT_BUILD_DIR}/properties/as/as.properties')
#loadProperties('${ANT_BUILD_DIR}/properties/machine/machine.properties')
#loadProperties('${ANT_BUILD_DIR}/properties/overload/overload.properties')
# serverlist = ${ANT_SERVER_NAMES}

#################################################
# Does the setup of the overload 
#################################################
def setupOverload(server):
    print 'Setting Overload for ' + server
    try:
        edit()
        startEdit()
        cd('/Servers/' + server + '/OverloadProtection/' + server)
        print 'Setting setPanicAction'
        cmo.setPanicAction(setPanicAction)
        print 'Setting '
        cmo.setFreeMemoryPercentHighThreshold(setFreeMemoryPercentHighThreshold)
        print 'Setting '
        cmo.setFailureAction(setFailureAction)
        print 'Setting '
        cmo.setFreeMemoryPercentLowThreshold(setFreeMemoryPercentLowThreshold)
        print 'Setting '
        cmo.createServerFailureTrigger()
                
        cd('/Servers/' + server + '/OverloadProtection/' + server + '/ServerFailureTrigger/' + server)
        print 'Setting '
        cmo.setMaxStuckThreadTime(setMaxStuckThreadTime)
        print 'Setting '
        cmo.setStuckThreadCount(setStuckThreadCount)
        activate()
    except:
        print 'Failed to set Overlaod protection for ' + server

connect(as_user, as_password, as_url)        
for server in serverlist:
    setupOverload(server) 
        